package com.uiotsoft.small.app.sampler.mqtt;

import com.uiotsoft.small.app.entity.AppClient;
import org.apache.jmeter.protocol.java.sampler.AbstractJavaSamplerClient;
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.threads.JMeterContextService;
import org.apache.jmeter.threads.JMeterVariables;

public class GetResultSampler extends AbstractJavaSamplerClient {
    @Override
    public SampleResult runTest(JavaSamplerContext javaSamplerContext) {
        JMeterVariables vars = JMeterContextService.getContext().getVariables();
        AppClient appClient = (AppClient) vars.getObject("appClient");
        SampleResult results = new SampleResult();
        results.sampleStart();
        if (appClient != null){
            results.sampleEnd();
            results.setSuccessful(true);
            results.setResponseData(appClient.getMyMqttClient().getDcCount()+"", "UTF-8");
        }
        return results;
    }
}
